<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* vue-iclient (https://github.com/SuperMap/vue-iclient)
* mapbox-gl-enhance (https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.1-12/mapbox-gl-enhance.js)
*********************************************************************-->
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title data-i18n='resources.title_componentsSlideshow_Vue'></title>
    <script type="text/javascript" include="vue" src="../js/include-web.js"></script>
    <script include="iclient-mapboxgl-vue,mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
    <style>
        #main {
            margin: 0 auto;
            width: 100%;
            height: 100%;
        }

        .sm-component-slideshow {
            position: absolute;
            top: 40px;
            left: 30px;
            width: 400px;
            height: 380px;
            border-radius: 4px;
        }
    </style>
</head>

<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
    <div id="main">
        <sm-web-map map-id='567946816' :map-options="mapOptions" server-url='https://www.supermapol.com'
            tianditu-key='1d109683f4d84198e37a38c442d68311' @load="mapLoaded">
        </sm-web-map>
        <sm-slideshow v-if="content.length > 0" :collapsed="false" :autoplay="autoplay" :pagination="pagination"
            @change="slideChange">
            <sm-slideshow-item v-for="item of content" :key="item.title">
                <h3 style="margin-top: 8px;">{{ item.title }}</h3>
                <p style="padding: 8px;">{{ item.description }}</p>
                <img :src="item.image" style="width: 300px; height: 170px;" />
            </sm-slideshow-item>
        </sm-slideshow>
    </div>

    <script>
        new Vue({
            el: '#main',
            data() {
                return {
                    mapOptions: {
                        zoom: 14,
                        pitch: 60,
                        center: [103.93424623295097, 33.03730377719067]
                    },
                    content: '',
                    pagination: {
                        el: '.swiper-pagination',
                        type: 'bullets',
                        clickable: true
                    },
                    autoplay: {
                        delay: 3000,
                        disableOnInteraction: false
                    }
                };
            },
            created() {
                this.setDataFn = this.setData.bind(this);
                this.getData(this.setDataFn);
            },
            beforeDestroy() {
                this.marker && this.marker.remove() && (this.marker = null);
            },
            methods: {
                getData(cb) {
                    var jsonName = /en/.test(SuperMap.Lang.getCode()) ? 'jiuzhai-en' : 'jiuzhai';
                    $.get(`../data/jiuzhai/${jsonName}.json`, function (res) {
                        cb && cb(res);
                    });
                },
                setData(res) {
                    this.content = res;
                },
                slideChange(options) {
                    let coordinates = this.content[options.realIndex].coordinates;
                    this.map.flyTo({ center: coordinates });
                    if (!this.marker) {
                        this.marker = new mapboxgl.Marker()
                            .setLngLat(coordinates)
                            .addTo(this.map);
                    } else {
                        this.marker.setLngLat(coordinates)
                    }
                },
                mapLoaded(e) {
                    this.map = e.map;
                    this.slideChange({ realIndex: 0 });
                }
            }
        })
    </script>
</body>

</html>